﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class Retrainment : ISerializable
    {
        private EducationInstitution organisationField;

        private SertificateSpeciality educationSpecialityField;

        private string diplomaSerieField;

        private string diplomaNumberField;

        private decimal hoursField;

        private decimal trainingDateField;

        private Employee employeeField;

        private static readonly Retrainment theOneObject = new Retrainment();

        public static Retrainment GetRetrainment()
        {
            return theOneObject;
        }
        /// <remarks/>
        public EducationInstitution Organisation
        {
            get
            {
                return this.organisationField;
            }
            set
            {
                this.organisationField = value;
            }
        }

        /// <remarks/>
        public SertificateSpeciality EducationSpeciality
        {
            get
            {
                return this.educationSpecialityField;
            }
            set
            {
                this.educationSpecialityField = value;
            }
        }

        /// <remarks/>
        public string DiplomaSerie
        {
            get
            {
                return this.diplomaSerieField;
            }
            set
            {
                this.diplomaSerieField = value;
            }
        }

        /// <remarks/>
        public string DiplomaNumber
        {
            get
            {
                return this.diplomaNumberField;
            }
            set
            {
                this.diplomaNumberField = value;
            }
        }

        /// <remarks/>
        public decimal Hours
        {
            get
            {
                return this.hoursField;
            }
            set
            {
                this.hoursField = value;
            }
        }

        /// <remarks/>
        public decimal TrainingDate
        {
            get
            {
                return this.trainingDateField;
            }
            set
            {
                this.trainingDateField = value;
            }
        }

        public Employee Employee
        {
            get
            {
                return employeeField;
            }
            set
            {
                employeeField = value;
            }
        }
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("Organisation", organisationField);
            info.AddValue("EducationSpeciality", educationSpecialityField);
            info.AddValue("DiplomaSerie", diplomaSerieField);
            info.AddValue("DiplomaNumber", diplomaNumberField);
            info.AddValue("Hours", hoursField);

        }
        public Retrainment()
        {
        }
        public List<Classes.Retrainment> getRetrainmentList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var Retrainment in emp.EmployeeRetrainment)
                {
                    Retrainment.Employee = emp;
                }
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.SelectMany(em => em.EmployeeRetrainment).ToList();

            return cr;
        }
    }
}
